using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ChangeSoundLib : MonoBehaviour
{
    public AudioClip[] soundFX;
    public AudioSource SFX;
    public GameObject text;
    public AudioSource soundSource;

    public Sprite[] btn_img;
    string[] names = {"钢琴", "风物之诗琴", "老旧的诗琴", "镜花之琴"};
    int id = 0;
    public void ToLeft()
    {
        id += names.Length - 1;
        id %= names.Length;
        switch (id)
        {
            case 0:
                soundSource.volume = 0.3f;
                SetBtnImg_Normal();
                break;
            case 1:
                soundSource.volume = 1;
                SetBtnImg_Normal();
                break;
            case 2:
                soundSource.volume = 1;
                SetBtnImg_GenshinOldPiano();
                break;
            case 3:
                soundSource.volume = 1;
                SetBtnImg_JinghuaPiano();
                break;
        }
        text.GetComponent<Text>().text = names[id];
        PlaySound.soundLibId = id;
        SFX.PlayOneShot(soundFX[0]);
    }
    
    public void ToRight()
    {
        id++;
        id %= names.Length;
        switch (id)
        {
            case 0:
                soundSource.volume = 0.3f;
                SetBtnImg_Normal();
                break;
            case 1:
                soundSource.volume = 1;
                SetBtnImg_Normal();
                break;
            case 2:
                soundSource.volume = 1;
                SetBtnImg_GenshinOldPiano();
                break;
            case 3:
                soundSource.volume = 1;
                SetBtnImg_JinghuaPiano();
                break;
        }
        text.GetComponent<Text>().text = names[id];
        PlaySound.soundLibId = id;
        SFX.PlayOneShot(soundFX[0]);
    }

    void Start()
    {
        text.GetComponent<Text>().text = names[1];
        id = 1;
        PlaySound.soundLibId = id;
    }

    public void justPlaySFX(int id)
    {
        SFX.PlayOneShot(soundFX[id]);
    }

    void SetBtnImg_Normal()
    {
        GameObject tmp;
        for (int i = 0; i < 21; i++)
        {
            tmp = GameObject.Find((i / 7).ToString() + (i % 7).ToString());
            tmp.GetComponent<Image>().sprite = btn_img[i % 7];
        }
    }

    void SetBtnImg_GenshinOldPiano()
    {
        GameObject tmp;
        for (int i = 0; i < 21;i++)
        {
            tmp = GameObject.Find((i / 7).ToString() + (i % 7).ToString());
            tmp.GetComponent<Image>().sprite = btn_img[i % 7 + 7];
        }
        GameObject.Find("01").GetComponent<Image>().sprite = btn_img[14];
    }

    void SetBtnImg_JinghuaPiano()
    {
        GameObject tmp;
        for (int i = 0; i < 21; i++)
        {
            tmp = GameObject.Find((i / 7).ToString() + (i % 7).ToString());
            tmp.GetComponent<Image>().sprite = btn_img[i % 7 + 15];
        }
    }
}
